package com.ldc.commonlibs.uts

import android.os.Handler
import android.os.Message

object MessageUts {
    fun <T> sendMessage(handler: Handler, what: Int, data: T?, arg1: Int, arg2: Int) {
        val message = handler.obtainMessage(what, data)
        message.arg1 = arg1
        message.arg2 = arg2
        handler.sendMessage(message)
    }


    fun sendMessage(handler: Handler, what: Int) {
        sendMessage(handler, what, null, -1, -1)
    }

    fun <T> sendMessage(handler: Handler, what: Int, data: T?) {
        sendMessage(handler, what, data, -1, -1)
    }

    fun sendMessage(handler: Handler, message: Message) {
        handler.sendMessage(message)
    }

    fun <T> sendMessageDelayed(
        handler: Handler,
        what: Int,
        data: T?,
        arg1: Int,
        arg2: Int,
        delayMillis: Long
    ) {
        val message = handler.obtainMessage(what)
        message.obj = data
        message.arg1 = arg1
        message.arg2 = arg2
        handler.sendMessageDelayed(message, delayMillis)
    }

    fun sendMessageDelayed(
        handler: Handler,
        what: Int,
        delayMillis: Long
    ) {
        sendMessageDelayed(handler, what, null, -1, -1, delayMillis)
    }

}